#include <bits/stdc++.h>
using namespace std;
int a[2000000];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int maxx = 0;
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    sum += a[i];

    if (sum < 0) {
      sum = 0;
    } else {
      maxx = max(maxx, sum);
    }
  }
  cout << maxx;
  return 0;
}